import 'package:flutter/material.dart';
import 'package:flutter_smart_heating/ui/ui.dart';
import 'package:get/get.dart';

import 'logic.dart';
import 'state.dart';

class FeedbackPage extends StatelessWidget {
  final FeedbackLogic logic = Get.put(FeedbackLogic());
  final FeedbackState state = Get.find<FeedbackLogic>().state;

  FeedbackPage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('反馈建议'),
      ),
      body: UiLifeCycle(
        onRouteDone: () {
          state.isReady = true;
          logic.update(['form']);
        },
        child: ListView(
          padding: const EdgeInsets.symmetric(horizontal: UiTheme.spacingX),
          children: [
            const SizedBox(
              height: UiTheme.toolbarSpacing,
            ),
            GetBuilder<FeedbackLogic>(
              id: 'form',
              builder: (context) {
                return UiPanel(
                  padding: const EdgeInsets.symmetric(horizontal: 10),
                  child: state.isReady
                      ? TextField(
                          maxLines: 8,
                          decoration: const InputDecoration(
                            hintText: '请详细描述您的问题或建议',
                            border: InputBorder.none,
                          ),
                          style: const TextStyle(fontSize: 15),
                          onChanged: (value) {
                            state.content = value;
                          },
                        )
                      : Container(
                          padding: const EdgeInsets.symmetric(vertical: 14),
                          height: 208,
                          child: const Opacity(
                            opacity: 0.6,
                            child: Text(
                              '请详细描述您的问题或建议',
                              style: TextStyle(
                                fontSize: 15,
                              ),
                            ),
                          ),
                        ),
                );
              },
            ),
            const SizedBox(height: 20),
            UiUploader(
              max: 4,
              onChanged: (files) {
                state.attachment = files;
              },
            ),
            const SizedBox(height: 20),
            GetBuilder<FeedbackLogic>(
              id: 'submit',
              builder: (context) {
                return SizedBox(
                  height: 45,
                  child: UiButton(
                      onPressed: logic.submit,
                      loading: state.loading,
                      child: Text(
                        '提交'.tr,
                        style: const TextStyle(
                          fontSize: 16,
                        ),
                      )),
                );
              },
            )
          ],
        ),
      ),
    );
  }
}
